home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / mknews10.zip / MAKENEWS.PAS < prev   
Pascal/Delphi Source File  |  1994-02-26  |  3KB  |  161 lines

  1. program makenews;  {turn files into a newsgroup}
  2.  
  3. {
  4.  
  5. to turn single-message-per-file mail into a newsgroup-type structure,
  6.   use this program alone.
  7. to turn MMDF multiple-messages-per-file mail into a newsgroup-type
  8.   structure, use this program after a program which will break the
  9.   MMDF mailbox into separate files.  check for `explode' or the like.
  10.  
  11. I use this to turn my incoming mail into a newsgroup, so I can use my
  12.   newsreader to read it (and thread it, and the like).  I like the
  13.   interface better.
  14.  
  15. v1.0
  16.  
  17. Russell Schulz
  18. russell@alpha3.ersys.edmonton.ab.ca (930226)
  19.  
  20. }
  21.  
  22. uses dos;
  23.  
  24. const
  25.   bufsize=1024;
  26.  
  27. var
  28.   parm: integer;
  29.   basedir: string;
  30.   fileinfo: searchrec;
  31.   tempi: integer;
  32.   filespec: string;
  33.   buffer: array[1..bufsize] of char;
  34.  
  35. procedure usage;
  36.  
  37. begin
  38.   writeln('usage:  makenews directory filespec [filespec ...]');
  39.   writeln('eg.  makenews d:\news\foo\mail\joe d:\user\joe\joe.*');
  40.   halt(1);
  41. end;
  42.  
  43. procedure copyfile(oldfn,newfn: string);
  44.  
  45. var
  46.   infile, outfile: file;
  47.   done: boolean;
  48.   numread: word;
  49.  
  50. begin
  51.   assign(infile,oldfn);
  52.   reset(infile,1);
  53.   assign(outfile,newfn);
  54.   rewrite(outfile,1);
  55.   done := false;
  56.   while not done do
  57.     begin
  58.       blockread(infile,buffer,bufsize,numread);
  59.       blockwrite(outfile,buffer,numread);
  60.       done := (numread<bufsize);
  61.     end;
  62.   close(infile);
  63.   close(outfile);
  64. end;
  65.  
  66. procedure movefile(oldfn,newfn: string);
  67.  
  68. var
  69.   f: file;
  70.  
  71. begin
  72.   copyfile(oldfn,newfn);
  73.   assign(f,oldfn);
  74.   erase(f);
  75. end;
  76.  
  77. function atoi(s: string): integer;
  78.  
  79. var
  80.   code: word;
  81.   result: integer;
  82.  
  83. begin
  84.   val(s,result,code);
  85.   atoi := result;
  86. end;
  87.  
  88. function integertozstring(i, width: integer): string;
  89.  
  90. var
  91.   result: string;
  92.  
  93. begin
  94.   str(i,result);
  95.   while length(result)<width do
  96.     result := '0'+result;
  97.   integertozstring := result;
  98. end;
  99.  
  100. function itoa(i: integer): string;
  101.  
  102. begin
  103.   itoa := integertozstring(i,0);
  104. end;
  105.  
  106. function max(a,b: integer): integer;
  107.  
  108. begin
  109.   if a<b then max := b else max := a;
  110. end;
  111.  
  112. function getuniqfile(basedir: string): string;
  113.  
  114. {basedir has to end in \}
  115.  
  116. var
  117.   result: integer;
  118.   fileinfo: searchrec;
  119.  
  120. begin
  121.   result := 0;
  122.   findfirst(basedir+'*',archive,fileinfo);
  123.   while doserror=0 do
  124.     begin
  125.       result := max(result,atoi(fileinfo.name));
  126.       findnext(fileinfo);
  127.     end;
  128.   getuniqfile := basedir+itoa(result+1);
  129. end;
  130.  
  131. procedure movetonews(filen: string);
  132.  
  133. begin
  134.   writeln(filen,' => ',getuniqfile(basedir));
  135.   movefile(filen,getuniqfile(basedir));
  136. end;
  137.  
  138. begin
  139.   if paramcount<2 then
  140.     usage;
  141.   basedir := paramstr(1)+'\';
  142.   for parm := 2 to paramcount do
  143.     begin
  144.       filespec := paramstr(parm);
  145.       tempi := length(filespec);
  146.       repeat
  147.         dec(tempi);
  148.       until (filespec[tempi]='\') or (filespec[tempi]=':') or (tempi<=1);
  149.       if (pos('\',filespec)=0) and (pos(':',filespec)=0) then
  150.         filespec:=''
  151.       else
  152.         filespec:=copy(filespec,1,tempi);
  153.       findfirst(paramstr(parm),archive,fileinfo);
  154.       while doserror=0 do
  155.         begin
  156.           movetonews(filespec+fileinfo.name);
  157.           findnext(fileinfo);
  158.         end;
  159.     end;
  160. end.
  161.